package com.zeng.ctrl.restmodel;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiRet {

    private int code;
    private String msg;
    private Object data;
    private boolean success;

    public static ApiRet successMsg(String msg, Object... args) {
        return success(String.format(msg, args));
    }

    public static ApiRet success(String msg) {
        return success(msg, null);
    }

    public static ApiRet success(String msg, Object data) {
        return new ApiRet(200, msg, data, true);
    }


    public static ApiRet failMsg(String msg, Object... args) {
        return fail(String.format(msg, args));
    }

    public static ApiRet fail(String msg) {
        return fail(msg, null);
    }

    public static ApiRet fail(String msg, Object data) {
        return new ApiRet(400, msg, data, false);
    }

}